import serial
import RPi.GPIO as GPIO
import time
import threading

# 创建串口对象
ser = serial.Serial('/dev/ttyS0', 9600)  # 根据需要修改串口路径和波特率
file_name = 'data.txt'
servo_pin = 18
GPIO.setmode(GPIO.BCM)  # BCM引脚编号模式
GPIO.setwarnings(False)

while 1:
    # 从串口读取数据
    if ser.isOpen():
        data = ser.readline().decode('utf-8')
        print("Received data:", data)
        with open(file_name, 'w') as f:
            f.write(data.replace('}\r\n', '').replace('{', ''))

